package com.guli.gulimall.gulimallproduct.controller;

import java.util.Arrays;
import java.util.Map;

import com.guli.common.utils.PageUtils;
import com.guli.common.utils.R;
import com.guli.gulimall.gulimallproduct.entity.SkuInfoEntity;
import com.guli.gulimall.gulimallproduct.service.SkuInfoService;
import com.guli.gulimall.gulimallproduct.vo.spuvo.SpuSaveVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * sku信息
 *
 * @author zouzhi
 * @email 1245268075@qq.com
 * @date 2022-04-03 10:19:08
 */
@RestController
@RequestMapping("gulimallproduct/skuinfo")
@Api(value = "SkuInfoController接口",tags = "sku信息")
public class SkuInfoController {
    @Autowired
    private SkuInfoService skuInfoService;

    /**
     * 列表
     */
    @ApiOperation(value = "查询商品",notes = "有关键字，按照关键字进行查询，没有关键字则进行全表分页查询")
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
//        PageUtils page = skuInfoService.queryPage(params);
        PageUtils page = skuInfoService.queryPageByCondition(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{skuId}")
    public R info(@PathVariable("skuId") Long skuId){
		SkuInfoEntity skuInfo = skuInfoService.getById(skuId);

        return R.ok().put("skuInfo", skuInfo);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody SkuInfoEntity skuInfo){
//		skuInfoService.save(skuInfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public R update(@RequestBody SkuInfoEntity skuInfo){
		skuInfoService.updateById(skuInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    public R delete(@RequestBody Long[] skuIds){
		skuInfoService.removeByIds(Arrays.asList(skuIds));

        return R.ok();
    }

}
